package sync1;

import java.util.concurrent.TimeUnit;

public class sync2 {

    public static void main(String[] args) {
        Sync2Cls s2 = new Sync2Cls();
//        Sync2Cls s3 = new Sync2Cls();
        new Thread(()->{
            try {
//                s2.fun1();
                Sync2Cls.sfun1();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },"thread1").start();
        new Thread(()->{
            try {
//                s2.fun2();
                Sync2Cls.sfun1();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },"thread2").start();
    }

}

class Sync2Cls {

    synchronized public void fun1() throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+" fun1 exec");
            Thread.sleep(100);
        }
    }

    synchronized public void fun2() throws InterruptedException {
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+" fun2 exec");
            Thread.sleep(100);
        }
    }
    synchronized public static void  sfun1() throws InterruptedException {

        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+" sfun1 exec");
            Thread.sleep(100);
        }
    }
}
